home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / elf11.zip / ELF11.ASM < prev    next >
Assembly Source File  |  1988-10-28  |  4KB  |  146 lines

  1. ;************************************************************************
  2. ;*                                    *
  3. ;*    ELF.A86.  This stupid program will set the specified error level*
  4. ;*    for batch files.  It has two modes of operation:  If invoked by:*
  5. ;*    ELF <CR> it will display: (Y/N)? on the screen & wait for one    *
  6. ;*    of these keys to be pressed.  It will then exit with errorlevel *
  7. ;*    255 if N was pressed, or error level 0 if Y was pressed.  With  *
  8. ;*    careful editing of prompts in a batch file, this can be used    *
  9. ;*    to make run-time operator decisions in batch files.        *
  10. ;*    The second invocation is:  ELF XX <CR>  Where XX is a two digit *
  11. ;*    HEXIDECIMAL number.  ELF will terminate with the specified    *
  12. ;*    error level.  This can add error level processing to programs    *
  13. ;*    that do not support it by chaining to ELF upon termination.    *
  14. ;*    Remember that the batch file ERRORLEVEL command only accepts    *
  15. ;*    decimal radix arguments.  Hex was used for ELF out of pure    *
  16. ;*    laziness on the part of the programmer!                *
  17. ;*    Written by:  Mark D. Pickerill  9 Sept. 1988.  The user bears    *
  18. ;*    all responsiblity for testing & use.  ELF stands for (E)rror    *
  19. ;*    (L)evel (F)ile, although the name was inspired by Tolkien,    *
  20. ;*    more than anything else.  COSMAC users take note!        *
  21. ;*                                    *
  22. ;************************************************************************
  23. ;
  24. ;v1.1, 28 Oct 88
  25. ; Toad Hall Tweak
  26. ; - reformatting to ASM/MASM format.
  27. ; - slight tweaks (in lower case or w/'TH' comments)
  28. ; David Kirschbaum
  29. ; Toad Hall
  30. ; kirsch@braggvax.ARPA
  31.  
  32. CR    EQU    0DH        ; Carriage return
  33. LF    EQU    0AH        ; Line feed
  34. EOF    EQU    1AH        ; End of file
  35.  
  36. CSEG    segment public para 'code'
  37.     assume    CS:Cseg, DS:Cseg, ES:Cseg
  38.  
  39.     ORG    0100H        ; Start of tpa
  40.  
  41. ELF    proc    near
  42.     JMP    short START    ; Jump past ego section
  43.  
  44.     DB    CR,LF,'ELF, Error Level File'
  45.     DB    CR,LF,'By M.D.P. 9 Sept. 1988'
  46.     db    CR,LF,'(Toad Hall Tweak, 881028',EOF
  47. Elf    endp
  48.  
  49. START    proc    near
  50. ;TH DS and CS are set to CS in .COM programs
  51. ;    PUSH    CS        ; Set data segment
  52. ;    POP    DS        ; It's set
  53. ;    PUSH    DS        ; Get this segment
  54. ;    POP    ES        ; And set es as well
  55.     cld            ;insure fwd
  56.     MOV    SI,0080H    ; Point to parameter field in psp
  57.     lodsb            ;get parameter length
  58.     or    al,al        ;any parm length?
  59.     JZ    NOPARMS        ; Do y/n
  60.  
  61.     xor    ch,ch        ;zero CH
  62.     mov    cl,al        ;parm length into CX for counter
  63. LOOP1:
  64.     lodsb            ; Get byte from parameter field
  65.     CMP    AL,' '        ; Space?
  66.     LOOPZ    LOOP1        ; Wait until you get a non-space char
  67.     JZ    NOPARMS        ; Do y/n
  68.     MOV    AH,AL        ; Get hex char
  69.     lodsb            ; Get next hex lsn
  70.     CALL    GETHEX        ; Convert to hex
  71.     XCHG    AH,AL        ; Store & retrieve msn
  72.     CALL    GETHEX        ; Convert
  73.     XCHG    AH,AL        ; Switch back
  74.     ADD    AH,AH        ; Compensate upper nybble
  75.     ADD    AH,AH
  76.     ADD    AH,AH
  77.     ADD    AH,AH        ; Ok, i`m tired of rotates!
  78.     OR    AL,AH        ; Ok we now have our number
  79.     MOV    AH,4CH        ; Mush dos terminate
  80.     INT    21H        ; Terminate with specified error level
  81. Start    endp
  82.  
  83.  
  84. GETHEX    proc    near
  85.     CMP    AL,2FH        ; <2f?
  86.     JL    TERM        ; Control, ignore
  87.     CMP    AL,46H        ; >46?
  88.     JG    TERM        ; Upper-case g or above, ignore
  89.     CMP    AL,39H        ; <39?
  90.     JLE    NUMBER        ; It's a number
  91.     CMP    AL,41H        ; <41?
  92.     JL    TERM        ; It's a punctuation, etc; ignore
  93. LETTER: ADD    AL,09H        ; 9 makes the lsn=hex version of input
  94. NUMBER: AND    AL,0FH        ; Strip msn, makes numbers hex & dumps
  95.                 ; Useless msn for letters
  96.     RET            ; Near
  97.  
  98. TERM:    MOV    AX,4C01H    ; Garbage parameters
  99.     INT    21H
  100. GetHex    endp
  101.  
  102.  
  103. MESSAGE    DB    '(Y/N)?$'    ; Question
  104.  
  105. NOPARMS    proc    near
  106.     MOV    AH,09H        ; Print string function
  107. ;    LEA    DX,MESSAGE    ; Point
  108.     mov    dx,offset message    ;msg offset
  109.     INT    21H        ; Do it
  110. NOPE:    MOV    AH,01H        ; Console input
  111.     INT    21H        ; Get char
  112.     AND    AL,5FH        ; Make upper case
  113. ;    CMP    AL,'Y'        ; Yes?
  114. ;    JZ    YES        ; Yes
  115. ;    CMP    AL,'N'        ; No?
  116. ;    JZ    NO        ; Yes
  117. ;    JMP    NOPE        ; Garbage, ignore
  118.     mov    ah,0FFH        ;assume no, errorlevel 0FFH
  119.     cmp    al,'N'        ;No?
  120.     jz    No
  121.     cmp    al,'Y'        ;Yes?
  122.     jnz    Nope        ; Garbage, ignore
  123. ;YES:
  124.     dec    ah        ;errorlevel now 0
  125. No:
  126.     mov    al,4CH        ;terminate
  127.     xchg    al,ah        ;AH=4CH, AL=errorlevel
  128.     push    ax        ;save
  129.  
  130. ;TH put CrLf function inline since now only used once.
  131.     MOV    AH,02H        ;CONOUT FUNCTION
  132.     MOV    DL,0DH        ;SEND CR
  133.     INT    21H        ;DO IT
  134. ;TH Svc 2, Int 21H, does not disturb AH
  135. ;    MOV    AH,02H        ;CONOUT FUNCTION
  136.     MOV    DL,0AH        ;SEND LF
  137.     INT    21H        ;DO IT
  138.  
  139.     pop    ax        ;set up for termination
  140.     INT    21H        ; We're history
  141. NoParms    endp
  142.  
  143.  
  144. Cseg    ENDS
  145.     end    Elf
  146.